﻿/*
REWRITTEN FROM SCRATCH BY PUSSYWIZARD, IT OWNS NOW!
*/

#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "ScriptedGossip.h"
#include "trial_of_the_crusader.h"
#include "Player.h"
#pragma execution_character_set("utf-8") 

enum MenuTexts
{
	MSG_ONE                         = 724000,
	//MSG_TESTED						= 724001,
	MSG_NEXT_STAGE					= 724001,
	MSG_CRUSADERS					= 724002,
	MSG_TWIN_VALKYR                 = 724003,
	MSG_ANUBARAK					= 724004,
	MSG_ONE2                        = 725000,
	//MSG_TESTED2						= 725001,
	MSG_NEXT_STAGE2					= 725001,
	MSG_CRUSADERS2					= 725002,
	MSG_TWIN_VALKYR2                = 725003,
	MSG_ANUBARAK2					= 725004,
};

class npc_announcer_toc10 : public CreatureScript
{
public:
	npc_announcer_toc10() : CreatureScript("npc_announcer_toc10") { }

	bool OnGossipHello(Player* pPlayer, Creature* pCreature)
	{
		if( !pCreature->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP) )
			return true;

		InstanceScript* pInstance = pCreature->GetInstanceScript();
		if( !pInstance )
			return true;

		uint32 gossipTextId = 0;
		switch( pInstance->GetData(TYPE_INSTANCE_PROGRESS) )
		{
			case INSTANCE_PROGRESS_INITIAL:
				gossipTextId = MSG_ONE;
				break;
			case INSTANCE_PROGRESS_INTRO_DONE:
			case INSTANCE_PROGRESS_BEASTS_DEAD:
				gossipTextId = MSG_NEXT_STAGE;
				break;
			case INSTANCE_PROGRESS_FACTION_CHAMPIONS_DEAD:
				gossipTextId = MSG_TWIN_VALKYR;
				break;
			case INSTANCE_PROGRESS_VALKYR_DEAD:
				gossipTextId = MSG_ANUBARAK;
				break;
			case INSTANCE_PROGRESS_JARAXXUS_DEAD:
				gossipTextId = MSG_CRUSADERS;
				break;
			case INSTANCE_PROGRESS_DONE:
				pCreature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
				return true;
			default:
				return true;
		}

		pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "是的, 我们已经准备好了迎接即将到来的挑战.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1337);
		pPlayer->SEND_GOSSIP_MENU(gossipTextId, pCreature->GetGUID());
		return true;
	}

	bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*sender*/, uint32 uiAction)
	{
		if( !pCreature->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP) )
			return true;

		InstanceScript* pInstance = pCreature->GetInstanceScript();
		if( !pInstance )
			return true;

		uint32 gossipTextId = 0;
		switch (pInstance->GetData(TYPE_INSTANCE_PROGRESS))
		{
		case INSTANCE_PROGRESS_INITIAL:
			gossipTextId = MSG_ONE2;
			break;
		case INSTANCE_PROGRESS_INTRO_DONE:
		case INSTANCE_PROGRESS_BEASTS_DEAD:
			gossipTextId = MSG_NEXT_STAGE2;
			break;
		case INSTANCE_PROGRESS_FACTION_CHAMPIONS_DEAD:
			gossipTextId = MSG_TWIN_VALKYR2;
			break;
		case INSTANCE_PROGRESS_VALKYR_DEAD:
			gossipTextId = MSG_ANUBARAK2;
			break;
		case INSTANCE_PROGRESS_JARAXXUS_DEAD:
			gossipTextId = MSG_CRUSADERS2;
			break;
		case INSTANCE_PROGRESS_DONE:
			pCreature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
			return true;
		default:
			return true;
		}

		switch (uiAction)
		{
		case GOSSIP_ACTION_INFO_DEF + 1337:
			pPlayer->PlayerTalkClass->ClearMenus();
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "开始迎接挑战吧!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1338);
			pPlayer->SEND_GOSSIP_MENU(gossipTextId, pCreature->GetGUID());
			break;
		case GOSSIP_ACTION_INFO_DEF + 1338:
			pInstance->SetData(TYPE_ANNOUNCER_GOSSIP_SELECT, 0);
			pCreature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);

			pPlayer->CLOSE_GOSSIP_MENU();
		}

		/*if( uiAction == GOSSIP_ACTION_INFO_DEF+1337 )
		{
			pInstance->SetData(TYPE_ANNOUNCER_GOSSIP_SELECT, 0);
			pCreature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
		}*/

		//pPlayer->CLOSE_GOSSIP_MENU();
		return true;
	}
};

void AddSC_trial_of_the_crusader()
{
	new npc_announcer_toc10();
}
